<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/11/13
 * Time: 10:54
 */

namespace Biz\service\activity;

use Biz\module\Packages\AllActivity\JinTie;
use Biz\pockets\constInterface\ActivityInfo;
use Biz\module\Packages\AllActivity\FlashSale;
use Biz\module\Packages\AllActivity\NewcomerExclusive;
use Biz\module\Packages\AllActivity\WeekPurchase;
use Biz\module\Packages\AllActivity\Tuan;
use Biz\module\Packages\AllActivity\MallTab;
use Biz\module\Packages\AllActivity\PingTuan;

class AllactivityInfoBak implements ActivityInfo
{
    public static function getActivityListByGoodsIds($goodsIds, $activityInfo)
    {
        $activityClass = self::getActivityType($activityInfo['activity_type']);
        $list = $activityClass::getActivityListByGoodsIds($goodsIds, $activityInfo);
        return $list;
    }

    public static function getActivityListBySkuIds($skuIds, $activityInfo)
    {
        $list = MallTab::getActivityListBySkuIds($skuIds, $activityInfo);
        return $list;
    }

    /**
     * 验证时间
     * @param $activityId
     * @param array $goodsIds
     * @param $activityTime
     * @param $type
     * @return mixed
     */
    public static function admCheckActivityTime(array $goodsIds, $activityTime, $type, $activityId = 0)
    {
        $activityClass = self::getActivityType($type);
        $result = $activityClass::checkActivityTime($goodsIds, $activityTime, $activityId);
        return $result;
    }

    /**
     * 验证活动的价格
     * @param $goodsInfo ['goods_id' => ['sku_id1' => '价钱', 'sku_id2' => '价钱'], ... ]
     * @param $activityTime ['start_time' => '开始时间', 'end_time' => '结束时间']
     * @param $type
     * @return mixed
     */
    public static function admCheckActivityPrice($goodsInfo, $activityTime, $type)
    {
        $activityClass = self::getActivityType($type);
        $result = $activityClass::checkActivityPrice($goodsInfo, $activityTime);
        return $result;
    }

    /**
     * 实现方式类似于工厂模式，提供更好的扩展性。
     * @param $type
     * @return JinTie | MallTab
     */

    public static function getActivityType($type)
    {
        switch ($type) {
            case ActivityInfo::ACTIVITY_TYPE_ZHUYOUJINTIE:
                return JinTie::class;
                break;
            case ActivityInfo::ACTIVITY_TYPE_LIMIT_TIME_ROB :
                return FlashSale::getActivityClass();
                break;
            case ActivityInfo::ACTIVITY_TYPE_NEWCOMER_EXCLUSIVE :
                return NewcomerExclusive::getActivityClass();
                break;
            case ActivityInfo::ACTIVITY_TYPE_WEEK_PURCHASE :
                return WeekPurchase::getActivityClass();
                break;
            case ActivityInfo::ACTIVITY_TYPE_TUAN :
                return Tuan::getActivityClass();
                break;
            case ActivityInfo::ACTIVITY_TYPE_NORMAL :
                return MallTab::getActivityClass();
                break;
            case ActivityInfo::ACTIVITY_TYPE_PINTUAN :
                return PingTuan::getActivityClass();
                break;
            default :
                return MallTab::class; // 不符合已上条件默认按照商城tab列表页的规则来返回
                break;
        }
    }
}